<?php include("_header.phtml") ?>

<div class="asset-search-container">
    <form method="get" action="edit">
        <div class="input-group">
            <input type="text" class="form-control" name="filter" placeholder="Search for..." value="<?php if(isset($params['filter'])) echo esc($params['filter']) ?>">
            <span class="input-group-btn">
                <button class="btn btn-primary" type="submit">Search</button>
            </span>
        </div>

        <div class="form-inline form-search">
            <div class="form-group">
                <label>Status</label>
                <?php foreach($constants['edit_status'] as $id => $status) if(is_int($id)) { ?>
                    <label class="form-checkbox">
                        <input type="checkbox" name="status[<?php echo esc($status) ?>]" value="1"
                            <?php if(isset($params['status']) && (is_array($params['status']) ?
                                isset($params['status'][$status]) && $params['status'][$status] :
                                in_array($status, explode(' ', $params['status'])))
                            ) echo 'checked=""';
                            ?>>
                        <?php echo esc(ucfirst(str_replace('_', ' ', $status))) ?>
                    </label>
                <?php } ?>
            </div>

            <?php if(isset($params['asset'])) { ?>
                <div class="form-group bg-info form-highlighted">
                    <label class="form-checkbox">
                        <input type="checkbox" name="asset" value="<?php echo esc($params['asset']) ?>" checked="">
                        <?php if($params['asset'] == -1) { ?>
                            Only new assets
                        <?php } else { ?>
                            Only asset #<?php echo esc($params['asset']) ?>
                        <?php } ?>
                    </label>
                </div>
            <?php } ?>

            <?php if(isset($params['user'])) { ?>
                <div class="form-group bg-info form-highlighted">
                    <label class="form-checkbox">
                        <input type="checkbox" name="user" value="<?php echo esc($params['user']) ?>" checked="">
                        Only by <?php echo esc($params['user']) ?>
                    </label>
                </div>
            <?php } ?>
        </div>
    </form>

    <div class="asset-search-results">
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th scope="col">Status</th>
                    <th scope="col">Type</th>
                    <th scope="col">Asset Name</th>
                    <th scope="col">Submit Date</th>
                    <th scope="col">Revision Date</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach($data['result'] as $i => $asset_edit) { ?>
                    <?php $submit_date = new DateTime($asset_edit['submit_date']); $modify_date = new DateTime($asset_edit['modify_date']); ?>
                    <tr>
                        <td class="table-tags">
                            <span class="label label-<?php
                            echo raw(['new' => 'info', 'in_review' => 'primary', 'rejected' => 'danger', 'accepted' => 'success'][$asset_edit['status']]) ?>">
                                <?php echo raw(ucfirst(str_replace('_', ' ', $asset_edit['status']))) ?>
                            </span>
                        </td>
                        <td><?php echo ($asset_edit['asset_id'] == -1 ? 'Create ' : 'Edit ') ?></td>
                        <td><a href="<?php echo raw($basepath) . '/asset/edit/' . url($asset_edit['edit_id']) ?>"><?php echo esc($asset_edit['title']) ?></a></td>
                        <td><?php echo raw($submit_date->format("Y-m-d")) ?></td>
                        <td><?php echo ($asset_edit['status'] === 'new') ? 'Pending' : raw($modify_date->format("Y-m-d")) ?></td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>

        <?php include("_pagination.phtml") ?>
    </div>
</div>

<?php include("_footer.phtml") ?>
